{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-2.16666667  0.66666667  0.5       ]\n",
      " [ 2.33333333 -0.33333333 -1.        ]\n",
      " [-0.5         0.          0.5       ]]\n",
      "[[ 1.  0.  0.]\n",
      " [ 0.  1.  0.]\n",
      " [ 0.  0.  1.]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "x = np.array([[1,2,3],[4,5,6],[1,2,5]]) \n",
    "y = np.linalg.inv(x) \n",
    "print (y) \n",
    "print (np.dot(x,y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  2.05500000e+03]\n",
      " [  1.66992188e+00]\n",
      " [ -3.36250000e+02]\n",
      " [ -2.52343750e+01]\n",
      " [ -1.58750000e+02]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from numpy.linalg import inv\n",
    "X= np.array([[1,850,5,25,3],[1,520,4,16,2],[1,580,3,40,4],[1,360,1,32,5]])\n",
    "y= np.array([[780],[690],[320],[300]])\n",
    "X_trans= X.transpose()\n",
    "theta = np.linalg.inv(X.transpose().dot(X)).dot(X_trans).dot(y)\n",
    "print(theta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 686.07421875])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "theta[0] + 850*theta[1] + 5*theta[2] + 25*theta[3] + 3*theta[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
